extends OrbitComponentBase
class_name OrbitToMouseComponent

@export var sprite:Sprite2D

func _orbit(_delta):
	var mouse_pos = get_global_mouse_position()
	var center_to_mouse = mouse_pos - rotation_center.global_position
	var center_to_mouse_dir = (center_to_mouse).normalized()
	var angle_in_radians = center_to_mouse_dir.angle()
	var offset := Vector2(cos(angle_in_radians), sin(angle_in_radians)) * radius
	global_position = rotation_center.global_position + offset
	look_at(mouse_pos)
	if sprite:
		_sprite_flip()

func _sprite_flip():
	if position.x > 0:
		sprite.flip_v = false
	elif position.x < 0:
		sprite.flip_v = true
